package model.forview;

import model.wrap.structure.Structure;
import models.ConstantName;
import models.ConstantValue;

public class StructureCreateModelForView extends ContentForMainTemplate
{
    public String title;
    public String description;
    public String idStructure = "";

    public String saveButton;
    public String cancelButton;

    public String titleLabel;
    public String descriptionLabel;

    public final String titleName = "title";
    public final String descriptionName = "description";

    public StructureCreateModelForView()
    {
	setDefaultValues();
    }
    
    public StructureCreateModelForView(Structure structure)
    {
	this.title = structure.getTitle();
	this.description = structure.getDescription();
	this.idStructure = String.valueOf(structure.getId());
	setDefaultValues();
    }
    
    public void setDefaultValues()
    {
	String title = ConstantValue
		.getConstantValue(ConstantName.STRUCTURE_CREATE_PAGE_TITLE);
	String header = ConstantValue
		.getConstantValue(ConstantName.STRUCTURE_CREATE_PAGE_HEADER);
	String footer = ConstantValue
		.getConstantValue(ConstantName.STRUCTURE_CREATE_PAGE_FOOTER);
	String userName = "";

	String tmp = "Создание";
	if(null != this.idStructure && !this.idStructure.equals(""))
	    tmp = "Изменение";
	
	title = title != null ? title : tmp+" иерархии";
	header = header != null ? header : tmp+" иерархии";
	footer = footer != null ? footer : tmp+" иерархии";

	titleLabel = ConstantValue
		.getConstantValue(ConstantName.STRUCTURE_CREATE_TITLE_LABEL);
	descriptionLabel = ConstantValue
		.getConstantValue(ConstantName.STRUCTURE_CREATE_DESCRIPTION_LABEL);
	saveButton = ConstantValue.getConstantValue(ConstantName.SAVE_BUTTON);
	cancelButton = ConstantValue
		.getConstantValue(ConstantName.CANCEL_BUTTON);

	titleLabel = titleLabel != null ? titleLabel : "Title";
	descriptionLabel = descriptionLabel != null ? descriptionLabel
		: "Description";
	saveButton = saveButton != null ? saveButton : "Save";
	cancelButton = cancelButton != null ? cancelButton : "Cancel";

	mainModelForView = new MainModelForView(title, userName, header, footer);
    }
}
